package com.example.hyg_veintype.utils.chartUtil;

import com.github.mikephil.charting.charts.LineChart;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author: yyw
 * time: 2020/12/18 16:44
 * desc: 缩放脉点，使其在图表内均匀分布
 */
public class OptimalChartUtils {
    /**
     * 设置最佳脉图
     *
     * @param pointList
     * @param chart
     */
    public static void setOptimalChart(List<Integer> pointList, LineChart chart) {
        List newPointList = new ArrayList();
        //缩放因子
        double _max = Collections.max(pointList);
        double _min = Collections.min(pointList);
        //Y轴缩放因子
        double _stepY = (_max - _min) / 150; //150 Y
        //X轴缩放因子
        double _stepX = 230 / pointList.size(); //230是X
        for (int i = 0; i < pointList.size(); i++) {
            newPointList.add(new AnalyseChartUtils.MyPoint(i * _stepX, (pointList.get(i) - _min) / _stepY));
        }
        AnalyseChartUtils.setData(chart, newPointList, 230, 150);
//        AnalyseChartUtils.setData(chart, newPointList, 150, 230);
    }

    /**
     * 设置包含最佳脉图的脉图
     *
     * @param pointList
     * @param chart
     */
    public static void setallChart(int bestSize,List<Integer> pointList, LineChart chart) {
        List newPointList = new ArrayList();
        for (int i = 0; i < pointList.size(); i++) {
            newPointList.add(new AnalyseChartUtils.MyPoint(i, pointList.get(i)));
        }
        AnalyseChartUtils.setData(chart, newPointList, pointList.size(), (int) (150*pointList.size()/bestSize));
    }
    /************** 前端代码 **************/
//    public PointCollection getSelectBrushFromData(int _startIndex, int _endIndex, List<int> _listData) {
//        if (_startIndex >= 0 && _endIndex - _startIndex > 0) {
//            PointCollection _pC = new PointCollection(_endIndex - _startIndex);
//            List<int> _list = new List<int>();
//            for (int i = _startIndex; i < _endIndex; i++) {
//                _list.Add(_listData[i]);
//            }
//            double _max = _list.Max();
//            double _min = _list.Min();
//            double _stepY = (_max - _min) / 150; //150 Y
//            double _stepX = 230 / _list.Count; //230是X
//            for (int i = 0; i < _list.Count; i++) {
//                _pC.Add(new System.Windows.Point(i * _stepX, (_list[i] - _min) / _stepY));
//            }
//            return _pC;
//        } else return null;
//    }
}
